package com.example.yuejian21.nongfusanquan.yuejian21.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

import com.example.yuejian21.nongfusanquan.yuejian21.adapter.PostAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Postbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Postmodel;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Usermodel;
import com.example.yuejian21.nongfusanquan.yuejian21.R;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by on 2017/9/27.
 */

public class PostFragment extends Fragment {
    private RecyclerView recyclerView;
    private View view = null;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_post, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局

        getData();
        return view;
    }


    private void getData() {
        Postmodel Model=new Postmodel();
        Call<List<Postbean>> call=Model.getPostlist();
        call.enqueue(new Callback<List<Postbean>>() {
            @Override
            public void onResponse(Call<List<Postbean>> call, Response<List<Postbean>> response) {
                List<Postbean> data = response.body();  //获取数据
                recyclerView.setAdapter(new PostAdapter(PostFragment.this.getActivity(), data));
            }

            @Override
            public void onFailure(Call<List<Postbean>> call, Throwable t) {

            }
        });

    }
}
